import com.test.platform.model.XTSReport
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import com.test.platform.network.RetrofitClient

class XTSReportRepository {
    private val apiService = RetrofitClient.apiService

    suspend fun getXTSReports(): List<XTSReport> {
        return withContext(Dispatchers.IO) {
            try {
                apiService.getAllXTSReports()  // 修改为正确的方法名
            } catch (e: Exception) {
                throw e
            }
        }
    }

    suspend fun createXTSReport(report: XTSReport): XTSReport {
        return withContext(Dispatchers.IO) {
            try {
                apiService.createXTSReport(report)
            } catch (e: Exception) {
                throw e
            }
        }
    }

    suspend fun updateXTSReport(id: Int, report: XTSReport): XTSReport {
        return withContext(Dispatchers.IO) {
            try {
                apiService.updateXTSReport(id, report)
            } catch (e: Exception) {
                throw e
            }
        }
    }

    suspend fun deleteXTSReport(id: Int): Boolean {
        return withContext(Dispatchers.IO) {
            try {
                apiService.deleteXTSReport(id)
                true
            } catch (e: Exception) {
                throw e
            }
        }
    }

    suspend fun getXTSReportById(id: Int): XTSReport {
        return withContext(Dispatchers.IO) {
            try {
                apiService.getXTSReportById(id)
            } catch (e: Exception) {
                throw e
            }
        }
    }
}